<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>药品管理</title>
</head>
<body>
<style>
	* {
		font-size: 12px;
	}
	
	.yzr-med-item{
		margin-top: 5px;
	}
</style>
<script type="text/javascript">
$(function(){		
		//打开添加药品的窗口
		$("#yzr-med-add").linkbutton({onClick: function(){
			$('#yzr-med-window').window({'title': "录入药品"});
			$('#yzr-med-form').form("clear");
			$("#yzr-med-window").window("open");
		}});
		
		//提交添加/编辑药品的请求
		$("#yzr-med-btnok").linkbutton({onClick: function(){
			var title = $('#yzr-med-window').window("options").title;
			var url = (title == '录入药品' ? 'addMedicine' : 'editMedicine');
			$('#yzr-med-form').form('submit', {
				url: url,
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	var json = eval("(" + data + ")");
					$.messager.alert("提示", json.reason);
					$('#yzr-med-window').window('close');
					$("#tb-medicine").datagrid("reload");
					$(this).form("clear");
			    }
			});
		}});
		
		//打开编辑药品的窗口
		$("#yzr-med-edit").linkbutton({onClick: function(){
			var rows = $("#tb-medicine").datagrid("getSelections");
			if(rows.length == 1){
				$('#yzr-med-window').window({'title': "编辑药品"});
				$('#yzr-med-window').window("open");
				var medId = rows[0].medId;
				$.getJSON("queryMedicineById", {"medId": medId}, function(data){
					$("#yzr-med-form").form("load", data);
				});
				
			}else{
				$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
			}
			
		}});
		
		//批量删除
		/* $("#yzr-med-delete").linkbutton({onClick: function(){
			var rows = $("#tb-medicine").datagrid("getSelections");
			if(rows.length >= 1){
				$.messager.confirm("提示", "确定要删除吗？", function(v){
					if(v){
						var rows = $("#tb-medicine").datagrid("getSelections");
						var arr = [];
						for(var i = 0; i < rows.length; i ++){
							arr.push(rows[i].medId);
						}
						$('<form>').form('submit', {
						    url:'delMedicine',
						    onSubmit: function(param){
						    	param.list = arr;
						    },
						    success:function(data){
						    	var json = eval("(" + data + ")");
								$.messager.alert("提示", json.reason);
								$("#tb-medicine").datagrid("reload");
						    }
						});
					}
				});
			}else{
				$.messager.alert("提示", "至少选择一条记录，您目前选择了" + rows.length + "条!");
			}
		}}); */
		
		//显示全部
		$("#yzr-med-reload").linkbutton({onClick:function(){
			$("#tb-medicine").datagrid({
	    		url: 'queryAllMedicine', 
	    		method: 'get'
	    	});
			
		}});
		
		//根据供应商名称模糊查询供应商 
		$('#yzr-med-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-medicine").datagrid({	    		
			    		url: name == 'name' ? 'queryMedicineByName' : 'queryMedicineByKind',
			    		method: 'post', 
			    		queryParams: {
			    			medName: value
			    	}});
		    		$('#yzr-med-search').searchbox('setValue', '');
		    	}
		    	
		    }
		}); 
		
	});
</script>


	<table id="tb-medicine" class="easyui-datagrid" 
		data-options="url:'queryAllMedicine',
			fitColumns:true,
			striped:true,
			fit:true,
			pagination: true,
			pageSize: 16,
			pageList: [16, 32, 48, 54],
			rownumbers: true,
			toolbar: '#yzr-med-tb',
			border:false
			">
		<thead>
			<tr>		
				<th data-options="field:'XXX',width:'5%', checkbox: true">药品编号</th>
				<th data-options="field:'medId',width:'25%',align:'center'">药品编号</th>
				<th data-options="field:'medName',width:'25%',align:'center'">药品名称</th>
				<th data-options="field:'medKind',width:'18%',align:'center'">类型</th>
				<th data-options="field:'medGuige',width:'15%',align:'center'">剂型</th>
				<th data-options="field:'medUnit',width:'15%',align:'center'">单位</th>				
			</tr>
		</thead>
	</table>
	
	<div id="yzr-med-tb">
		<a id="yzr-med-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加药品</a>
		<a id="yzr-med-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改药品</a>
		<!-- <a id="yzr-med-delete" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除药品</a> -->
		<a id="yzr-med-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input id="yzr-med-search" class="easyui-searchbox" data-options="menu: '#yzr-med-pName', width: 220, prompt: '请输入关键字'"/>
	</div>
	
	<div id="yzr-med-pName" style="width:140px">
	    <div data-options="name:'name'">药品名称</div>
	    <div data-options="name:'kind'">药品类型</div>
	</div>
	
	<!-- 添加/修改班级窗口 -->
	<div id="yzr-med-window" class="easyui-window" title="录入药品" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:400px;height:320px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="yzr-med-form" method="post">
					<div class="yzr-med-item" style="display:none;"><input name="medId" class="easyui-textbox" data-options="label: '药品编号', width: 200"></div>
					<div class="yzr-med-item"><input name="medName" class="easyui-textbox" data-options="label: '药品名称', width: 250, required:true"></div>
					<div class="yzr-med-item">
						<select class="easyui-combobox" name="medKind" data-options="label: '药品类型', width: 200, required:true,panelHeight:85">
						    <option value="西药">西药</option>
						    <option value="中药">中药</option>
						    <option value="注射剂">注射剂</option>
						    <option value="外用药">外用药</option>
						</select>
					</div>
					<div class="yzr-med-item">
						<select class="easyui-combobox" name="medGuige" data-options="label: '剂型', width: 200, required:true,panelHeight:225">
						    <option value="片剂">片剂</option>
						    <option value="颗粒">颗粒</option>
						    <option value="胶囊">胶囊</option>
						    <option value="口服液">口服液</option>
						    <option value="注射剂">注射剂</option>						    
						    <option value="喷剂">喷剂</option>
						    <option value="散剂">散剂</option>
						    <option value="软膏">软膏</option>
						    <option value="橡胶膏">橡胶膏</option>
						    <option value="卫材">卫材</option>					    
						    <option value="栓剂">栓剂</option>
						</select>
					</div>
					<div class="yzr-med-item">
						<select class="easyui-combobox" name="medUnit" data-options="label: '单位', width: 200, required:true,panelHeight:125">
						    <option value="盒">盒</option>
						    <option value="瓶">瓶</option>
						    <option value="袋">袋</option>
						    <option value="板">板</option>
						    <option value="片">片</option>						    
						    <option value="支">支</option>
						</select>
					</div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="yzr-med-btnok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >确定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#yzr-med-window').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
</body>
</html>